R Markdown

# Create the plot
gph <- plot_ly(UFP_39, x = ~OFFICER_YEARS_ON_FORCE, y = ~OFFICER_GENDER, type = "scatter", mode = "markers", color = ~OFFICER_GENDER, colors = c("#1F77B4", "#FF7F0E"))

# Add plot title and axis labels
gph1 <- gph %>% layout(title = "Officer Years on Force vs. Officer Gender", xaxis = list(title = "Officer Years on Force"), yaxis = list(title = "Officer Gender"))

# Display the plot
gph1

Flex dashboard

scatter plot

The code generates a scatter plot with the officer’s years of service on the x-axis and gender on the y-axis using the plot_ly function.